import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

/**
 * pridadi k jednotlivym menam referencii data z bibtexu
 * @author cerko
 *
 */
public class RefEvaluator {
	
	private BiBLoader library;
	
	public RefEvaluator(BiBLoader bib){
		library = bib;
	}
	
	/**
	 * pridadi k jednotlivym menam referencii data z bibtexu
	 * @param refs - set pouzitych referencii
	 * @return - mapa typu meno - data
	 */
	public Map<String, Data> assignData(Set<String> refs){
		ArrayList<String> sortedRefs = new ArrayList<String>(refs);
		Collections.sort(sortedRefs, String.CASE_INSENSITIVE_ORDER);
		Map<String, Data> usedRefs = new LinkedHashMap<String, Data>();
		
		for (String ref : sortedRefs){
			usedRefs.put(ref, library.getRefData(ref));
		}
		
		//debug veci
		
		/*
		for (Entry<String, Data> entry : usedRefs.entrySet()){
			String key = entry.getKey();
			Data value = entry.getValue();
			System.out.println("{" + key + " = " + value.toString() + " }");
		}
		*/
		
		return usedRefs;
	}
}
